package com.company;

import java.util.Scanner;

public class New {
    public static void main(String[] args) {


        for (; ; ) {
            System.out.println("Please select mode:Rational or Complex or Quit(R/C/Q)");
            Scanner scan = new Scanner(System.in);
            String s = scan.next();
            char ch = s.charAt(0);
            if (ch == 'R' || ch == 'r') {
                System.out.println("Please input 分子num1,num2,分母den1,den2: ");
                int num1 = scan.nextInt();
                int num2 = scan.nextInt();
                int den1 = scan.nextInt();
                int den2 = scan.nextInt();
                RationalNumber r1 = new RationalNumber(num1, den1);
                RationalNumber r2 = new RationalNumber(num2, den2);
                RationalNumber r3;
                RationalNumber r4;
                RationalNumber r5;
                RationalNumber r6;
                RationalNumber r7;
                System.out.println("First rational number: " + r1);
                System.out.println("Second rational number:" + r2);
                if (r1.isLike(r2))
                    System.out.println("r1 and r2 are equal.");
                else
                    System.out.println("r1 and r2 are not equal.");
                r3 = r1.reciprocal();
                System.out.println("The reciprocal of r1 is:" + r3);
                System.out.println("Please input the symbol:");
                String m = scan.next();
                switch (m) {
                    case "+":
                        r4 = r1.add(r2);
                        System.out.println("r1 +r2:" + r4);
                        break;
                    case "-":
                        r5 = r1.subtract(r2);
                        System.out.println("r1 -r2 :" + r5);
                        break;
                    case "*":
                        r6 = r1.multiply(r2);
                        System.out.println("r1 *r2 :" + r6);
                        break;
                    case "/":
                        r7 = r1.divide(r2);
                        System.out.println("r1 /r2 :" + r7);
                        break;
                }
            } else if (ch == 'C' || ch == 'c') {
                System.out.println("Please input 实部R1，R2虚部I1,I2: ");
                int R1 = scan.nextInt();
                int R2 = scan.nextInt();
                int I1 = scan.nextInt();
                int I2 = scan.nextInt();
                ComplexNumber r1 = new ComplexNumber(R1, I1);
                ComplexNumber r2 = new ComplexNumber(R2, I2);
                Boolean r3;
                ComplexNumber r4;
                ComplexNumber r5;
                ComplexNumber r6;
                ComplexNumber r7;
                System.out.println("First rational number: " + r1);
                System.out.println("Second rational number:" + r2);

                System.out.println("Choose calculation kind: (+ - * / >)");
                String m = scan.next();
                switch (m) {
                    case "+":
                        r4 = r1.ComplexAdd(r2);
                        System.out.println("r1 +r2:" + r4);
                        break;
                    case "-":
                        r5 = r1.ComplexSub(r2);
                        System.out.println("r1 -r2 :" + r5);
                        break;
                    case "*":
                        r6 = r1.ComplexMulti(r2);
                        System.out.println("r1 *r2 :" + r6);
                        break;
                    case "/":
                        r7 = r1.ComplexDiv(r2);
                        System.out.println("r1 /r2 :" + r7);
                        break;
                    case ">":
                        r3 = r1.Compare(r2);
                        if (r3 == true)
                            System.out.println("r1<r2");
                        else
                            System.out.println("r2>r1");
                        break;
                }
            }
            else
                break;
        }
    }
}
